package com.cyx.exercise.ollama;

import java.io.IOException;

/**
 * 快速测试类 - 验证修复后的JSON解析
 */
public class QuickTest {
    
    public static void main(String[] args) {
        String baseUrl = "http://localhost:11434";
        String model = "qwen3:4b";
        
        System.out.println("=== 快速测试修复后的Ollama客户端 ===");
        System.out.println("使用模型: " + model);
        System.out.println();
        
        OllamaClient client = new OllamaClient(baseUrl);
        
        try {
            // 测试1: 简单问题
            System.out.println("测试1: 简单数学问题");
            OllamaRequest request1 = new OllamaRequest(model, "1+1等于几？请直接回答数字。");
            OllamaResponse response1 = client.generate(request1);
            
            System.out.println("问题: " + request1.getPrompt());
            System.out.println("完整响应: " + response1.getResponse());
            System.out.println("完成状态: " + response1.isDone());
            System.out.println("响应长度: " + response1.getResponse().length() + " 字符");
            System.out.println();
            
            // 测试2: 聊天接口
            System.out.println("测试2: 聊天接口");
            OllamaChatRequest chatRequest = new OllamaChatRequest(model);
            chatRequest.addSystemMessage("你是一个简洁的助手，请用一句话回答问题。");
            chatRequest.addUserMessage("Java是什么？");
            
            OllamaChatResponse chatResponse = client.chat(chatRequest);
            
            System.out.println("用户: Java是什么？");
            System.out.println("助手: " + chatResponse.getMessage().getContent());
            System.out.println("角色: " + chatResponse.getMessage().getRole());
            System.out.println("完成状态: " + chatResponse.isDone());
            System.out.println("响应长度: " + chatResponse.getMessage().getContent().length() + " 字符");
            System.out.println();
            
            // 测试3: 检查是否包含思考过程
            System.out.println("测试3: 检查响应内容");
            String content = response1.getResponse();
            if (content.contains("<think>")) {
                System.out.println("✓ 响应包含完整的思考过程");
                
                // 尝试提取实际回答（在</think>之后的内容）
                int thinkEndIndex = content.lastIndexOf("</think>");
                if (thinkEndIndex != -1) {
                    String actualAnswer = content.substring(thinkEndIndex + 8).trim();
                    System.out.println("实际回答部分: " + actualAnswer);
                } else {
                    System.out.println("未找到</think>结束标签");
                }
            } else {
                System.out.println("响应不包含思考过程，直接是答案");
            }
            
        } catch (IOException e) {
            System.err.println("网络错误: " + e.getMessage());
        } catch (InterruptedException e) {
            System.err.println("请求被中断: " + e.getMessage());
        } catch (Exception e) {
            System.err.println("其他错误: " + e.getMessage());
            e.printStackTrace();
        }
        
        System.out.println("\n=== 测试完成 ===");
    }
}
